﻿CREATE FUNCTION dbo.NLin_NSIMeter
	(
	@ID int
	)
RETURNS int
AS
	BEGIN
	DECLARE @linksCount int
	
	SELECT @linksCount = COUNT(ID) FROM NSI_PRODUCT WHERE NSI_METER_ID = @ID
	
	SELECT @linksCount = @linksCount + COUNT(ID) FROM NSI_SERVICE WHERE NSI_METER_ID = @ID
	
	SELECT @linksCount = @linksCount + COUNT(ID) FROM NSI_MATERIAL WHERE NSI_METER_ID = @ID
	
	RETURN @linksCount
	END
